package javase2.day02;

import java.io.File;
import java.util.Arrays;
import java.util.Comparator;

/**
 * File �ṩ�����ļ��е����ݵķ���
 *   listFiles() == ls
 * 
 */
public class Demo6 {
  public static void main(String[] args) {
    //String path = "/etc";
    String path = "C:/windows";
    File dir = new File(path);
    File[] files = dir.listFiles();//ls dir
    Comparator<File> byName = new Comparator<File>(){
      public int compare(File o1, File o2) {
        //���o1,o2�����ļ��л��ļ��������ļ�(��)��Ƚ�
        //����Ļ��ļ��б��ļ�С��o1���ļ��оͷ���-1
        if(o1.isFile()==o2.isFile()){
          //return o1.compareTo(o2);//�ļ�Ĭ�ϰ����ļ���Ƚ�
          return o1.getName().compareTo(o2.getName());
        }
        return o1.isDirectory() ? -1 : 1;
      }
    };
    Arrays.sort(files, byName);
//    for(int i=0; i<files.length; i++){
//      File file = files[i];
    for(File file:files){//java 5 �ṩforeach���
      if(file.isDirectory()){
        System.out.println("["+file.getName()+"]");
      }else{
        System.out.println(file.getName());
      }
    }
  }
}





